#include <iostream>
#include <cstring>
using namespace std;
// zdl:: 难点就是增加了环形数组的处理方式，这里就需要使用倍增的思想（复写）
int n;
const int N = 210;
int s[N], sum[N];
int f[N][N], g[N][N]; // 找到最大值和最小值
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        s[i + n] = s[i];
    }

    // zdl:: 处理前缀和数组
    int m = 2 * n;
    for (int i = 1; i <= m; i++)
        sum[i] = sum[i - 1] + s[i];
    // 初始化数组
    memset(f, -0x3f, sizeof f);
    memset(g, 0x3f, sizeof g);
    for (int i = 0; i <= m; i++)
        g[i][i] = f[i][i] = 0;

    // zdl:: 开始动态规划
    for (int len = 1; len <= n; len++)
    {
        for (int i = 1; i + len - 1 <= m; i++)
        {
            int j = i + len - 1;
            int t = sum[j] - sum[i - 1];
            for (int k = i; k < j; k++)
            {
                f[i][j] = max(f[i][j], f[i][k] + f[k + 1][j] + t);
                g[i][j] = min(g[i][j], g[i][k] + g[k + 1][j] + t);
            }
        }
    }
    // zdl:: 现在开始枚举相应的字典，然后进行判断
    int ret1 = 0x3f3f3f, ret2 = -ret1;
    for (int i = 1; i <= n; i++)
    {
        // 最大值：
        ret2 = max(ret2, f[i][i + n - 1]);
        // 最小值
        ret1 = min(ret1, g[i][i + n - 1]);
    }

    cout << ret1 << endl
        << ret2 << endl;
    return 0;
}

// zdl:: then it's all ok!!!